<template>
  <div class="line-detail">
    <span class="table-blue" @click="back">
      <i class="iconfont icon-left"></i>返回
    </span>
    <Form class="businessForm" :model="busSetting" label-position="right" :label-width="140">
      <div v-if="edit">
        <div class="title">Id配置</div>
        <div class="box">
          <Row>
            <i-col span="18">
              <Row>
                <i-col span="12">
                  <FormItem label="Model_Id">
                    <Row>
                      <i-col span="24">
                        <i-input v-model="busSetting.modelId" :disabled="edit"></i-input>
                      </i-col>
                    </Row>
                  </FormItem>
                </i-col>
              </Row>
            </i-col>
          </Row>
        </div>
      </div>
      <div class="title">类型配置</div>
      <div class="box">
        <Row>
          <i-col span="18">
            <Row>
              <i-col span="12">
                <FormItem label="类型">
                  <Row>
                    <i-col span="24">
                      <Select v-model="busSetting.modelType" style="width:200px" :disabled="edit">
                        <Option v-for="item in typeList" :value="item.ename" :key="item.cname">{{ item.cname }}</Option>
                      </Select>
                    </i-col>
                  </Row>
                </FormItem>
              </i-col>
            </Row>
          </i-col>
        </Row>
      </div>
      <div class="title">基础配置</div>
      <div class="box">
        <Row>
          <i-col span="18">
            <Row>
              <i-col span="12">
                <FormItem label="业务名称" v-if="busSetting.modelType === 'task'">
                  <Row>
                    <i-col span="24">
                      <i-input v-model="busSetting.modeName" placeholder="业务标注方式名称"></i-input>
                    </i-col>
                  </Row>
                </FormItem>
                <FormItem label="勋章名称" v-if="busSetting.modelType === 'medal'">
                  <Row>
                    <i-col span="24">
                      <i-input v-model="busSetting.modeName" placeholder="勋章名称"></i-input>
                    </i-col>
                  </Row>
                </FormItem>
              </i-col>
              <i-col span="12">
                <FormItem label="简短描述">
                  <Row>
                    <i-col span="24">
                      <i-input v-model="busSetting.describe" placeholder="简短描述"></i-input>
                    </i-col>
                  </Row>
                </FormItem>
              </i-col>
            </Row>
          </i-col>
        </Row>
      </div>

      <div class="title" v-if="busSetting.tasks">业务配置</div>

      <div class="box">
        <Row>
          <i-col span="18">
            <Row>
              <i-col span="12" v-for="(value,key) in busSetting.tasks" :key="key + 'aaaaa'">
                <FormItem v-if="taskflowNode.indexOf(key)=='-1' && key != 'flow'" :label="cname[key]">
                  <Row>
                    <i-col span="24">
                      <i-input v-model="busSetting.tasks[key]" :placeholder="key"></i-input>
                    </i-col>
                  </Row>
                </FormItem>
                <FormItem v-else-if="taskflowNode.indexOf(key)!='-1' && key != 'flow'" :label="cname[key]">
                  <Row>
                    <i-col span="24">
                      <i-select filterable v-model="busSetting.tasks[key]" placeholder="请选择">
                        <i-option v-for="(item,index) in pipelineList" :key="item.id+index+key" :value="item.id">{{item.name}}</i-option>
                      </i-select>
                    </i-col>
                  </Row>
                </FormItem>
              </i-col>
              <i-col span="24">
                <FormItem label="业务线批次配置项">
                  <Button type="primary" size="small" @click="openOuterConfig" style="margin-right: 20px;">添加</Button>
                  <Tag type="border" closable color="success" v-for="(tags, ind) in filterConifgInfo" :key="ind" @on-close="handleClose(tags)">{{tags.cname}}</Tag>
                </FormItem>
              </i-col>
            </Row>
          </i-col>
        </Row>
        <!-- 创建批次配置项设置 -->
      </div>
      <!-- 流转设置 -->
      <div class="title">后处理</div>
      <div class="box">
        <Row>
          <i-col span="18">
            <Row>
              <i-col span="12">
                <FormItem v-for="(item, index) in busSetting.flowTask" :key="index">
                  <Row>
                    <i-col span="18">
                      <i-select filterable v-model="item.value" placeholder="请选择" @on-change="changeFlowTask(item)">
                        <i-option v-for="(items,indexs) in pipelineList" :key="indexs" :value="items.id">{{items.name}}</i-option>
                      </i-select>
                    </i-col>
                    <i-col span="4" offset="1">
                      <Button @click="handleRemove(index)">删除</Button>
                    </i-col>
                  </Row>
                </FormItem>
                <FormItem>
                  <Row>
                    <i-col span="12">
                      <Button type="dashed" long @click="handleAdd()" icon="md-add">增加</Button>
                    </i-col>
                  </Row>
                </FormItem>
              </i-col>
            </Row>
          </i-col>
        </Row>
      </div>
      <!--回收转移放弃-->
      <div class="title">回收配置</div>

      <div class="box">
        <Row>
          <i-col span="21">
            <Row>
              <i-col span="6">
                <FormItem label="提交已标注">
                  <Row>
                    <i-col span="24">
                      <Checkbox v-model="flow[0].recovery.isSubmitProcessed" @on-change="recoveryChange">
                        <span v-if="flow[0].recovery.isSubmitProcessed">是</span>
                        <span v-else>否</span>
                      </Checkbox>
                    </i-col>
                  </Row>
                </FormItem>
              </i-col>
            </Row>
          </i-col>
        </Row>
      </div>
      <div class="title">转移配置</div>

      <div class="box">
        <Row>
          <i-col span="21">
            <Row>
              <i-col span="6">
                <FormItem label="提交已标注">
                  <Row>
                    <i-col span="24">
                      <Checkbox v-model="flow[0].transfer.isSubmitProcessed" @on-change="transferChange">
                        <span v-if="flow[0].transfer.isSubmitProcessed">是</span>
                        <span v-else>否</span>
                      </Checkbox>
                    </i-col>
                  </Row>
                </FormItem>
              </i-col>
            </Row>
          </i-col>
        </Row>
      </div>
      <div class="title">放弃配置</div>

      <div class="box">
        <Row>
          <i-col span="21">
            <Row>
              <i-col span="5">
                <FormItem label="保存标注结果">
                  <Row>
                    <i-col span="24">
                      <Checkbox v-model="flow[0].giveup.isUpdateResult" @on-change="giveupMark">
                        <span v-if="flow[0].giveup.isUpdateResult == true">是</span>
                        <span v-else>否</span>
                      </Checkbox>
                    </i-col>
                  </Row>
                </FormItem>
              </i-col>
              <i-col span="5">
                <FormItem label="保存检查结果">
                  <Row>
                    <i-col span="24">
                      <Checkbox v-model="flow[1].giveup.isSaveResult" @on-change="giveupCheck">
                        <span v-if="flow[1].giveup.isSaveResult == true">是</span>
                        <span v-else>否</span>
                      </Checkbox>
                    </i-col>
                  </Row>
                </FormItem>
              </i-col>
              <i-col span="5">
                <FormItem label="保存质检结果">
                  <Row>
                    <i-col span="24">
                      <Checkbox v-model="flow[2].giveup.isSaveResult" @on-change="giveupTest">
                        <span v-if="flow[2].giveup.isSaveResult == true">是</span>
                        <span v-else>否</span>
                      </Checkbox>
                    </i-col>
                  </Row>
                </FormItem>
              </i-col>
            </Row>
          </i-col>
        </Row>
      </div>

      <div class="title">业务线设置</div>

      <RadioGroup v-model="busSetting.viewConfig.businessPageType" @on-change="businessCheckType" type="button" style="padding:0 140px;margin-bottom: 20px;">
        <Radio label="0">通用业务线</Radio>
        <Radio label="1">自定义业务线</Radio>
      </RadioGroup>
      <!-- 通用线路由版本配置 -->
      <div class="box" v-show="busSetting.viewConfig.businessPageType === '0'">
        <!--/回收转移放弃-->
        <div class="title">通用路由配置</div>
        <Row>
          <i-col span="18">
            <FormItem label="通用版本选择">
              <Row>
                <i-col span="10">
                  <i-select v-model="busSetting.views['viewMarkPage']" placeholder="请选择" @on-change="selectVersion">
                    <i-option v-for="(items,indexs) in historyViewList['viewMarkPage']" :key="items+indexs" :value="items">{{items}}</i-option>
                  </i-select>
                </i-col>
              </Row>
            </FormItem>
            <Row>
              <i-col span="12" v-for="(value,key) in busSetting.views" :key="key + 'bbbbb'">
                <FormItem :label="cname[key]">
                  <Row>
                    <i-col span="24">
                      <Select v-model="busSetting.views[key]" disabled>
                        <Option v-for="(item,index) in historyViewList[key]" :key="item+index" :value="item">{{item}}</Option>
                      </Select>
                    </i-col>
                  </Row>
                </FormItem>
              </i-col>
            </Row>
          </i-col>
        </Row>
      </div>
      <!-- 自定义业务线 模板与版本选择 -->
      <div class="box" v-show="busSetting.viewConfig.businessPageType === '1'">
        <div class="title">自定义模板配置</div>
        <Row>
          <i-col span="8">
            <FormItem label="模板选择">
              <Row>
                <i-col span="22">
                  <i-select v-model="busSetting.viewConfig.markTemplateId" placeholder="请选择" @on-change="selectTmp">
                    <i-option v-for="(items,indexs) in templateList" :key="indexs" :value="items.id">{{items.name}}</i-option>
                  </i-select>
                </i-col>
              </Row>
            </FormItem>
          </i-col>
          <i-col span="10">
            <FormItem label="模板版本选择">
              <Row>
                <i-col span="22">
                  <i-select v-model="busSetting.viewConfig.pageVersion" placeholder="请选择" @on-change="selectVersion">
                    <i-option v-for="(items,indexs) in tmpVersionList" :key="indexs" :value="items.version">v{{items.version}}</i-option>
                  </i-select>
                </i-col>
              </Row>
            </FormItem>
          </i-col>
        </Row>
      </div>
      <Row>
        <i-col span="18" style="text-align:left; margin:50px 0;">
          <Row>
            <i-col span="8">&nbsp;</i-col>
            <i-col span="8">
              <div style="padding-left:140px;">
                <Button type="primary" style="width:120px;" :loading="loading" size="large" @click="saveBusiness">提 交</Button>
              </div>
            </i-col>
            <i-col span="8">&nbsp;</i-col>
          </Row>
        </i-col>
      </Row>
    </Form>
    <!-- 外部设置 -->
    <Modal width="700px" v-model="outerVisual" title="业务线批次配置" footer-hide class="visual-outer-model">
      <Tabs value="config" v-show="conifgInfo.length>0">
        <TabPane label="基础配置" name="config">
          <CheckboxGroup v-model="busSetting.viewConfig.businessBatchConfig">
            <Checkbox v-for="check of conifgInfo" :key="check.ename" :label="check.ename">{{check.cname}}</Checkbox>
          </CheckboxGroup>
        </TabPane>
      </Tabs>
      <div class="visual-outer-footer">
        <Button @click="outerCancelHandler" style="margin-right:8px">取消</Button>
        <Button type="primary" @click="outerOkHandler">确定</Button>
      </div>
    </Modal>
  </div>
</template>

<script>
import {
  getListDetail,
  getKeys,
  saveListDetail,
  getPipeline
} from 'http/api/linemanage'
import { getTemplateList, getTemplateListVersion, delTemplateByVersion, delTemplate } from 'http/api/mark';
import { constants } from 'fs';

let conifgInfo = [{
  ename: 'integralSet',
  cname: '积分设置',
  class: 'integralSet'
}, {
  ename: 'termImport',
  cname: '术语导入',
  class: 'dataSelect'
}, {
  ename: 'languageType',
  cname: '语言类型',
  class: 'languageSet' // 配置归类 术语语言设置
}, {
  ename: 'machineTranslation',
  cname: '机器翻译',
  class: 'machine'
}];
export default {
  name: 'LineDetail',
  data() {
    return {
      edit: false,
      type: 'task',
      typeList: [
        { cname: '业务线', ename: 'task' },
        { cname: '勋章', ename: 'medal' }
      ],
      modelId: '',
      busSetting: {
        // 新增和编辑需要传递的参数
        modeName: '',
        modelId: '',
        modelType: 'task',
        describe: '',
        tasks: {
          createBatchTaskFlowId: '',
          taskExportTaskFlowId: '',
          recoveryStrategy: '',
          transferStrategy: '',
          createMedalTaskFlowId: '',
          integralHandle: ''
        },
        views: {
          viewMarkPage: '',
          viewCreateBatch: '',
          viewCreateMedal: '',
          viewExport: '',
          viewMarkTaskPage: '',
          viewMedalPage: '',
          viewMyIntegralDetail: '',
          viewResultPage: ''
        },
        flowTask: [],
        viewConfig: {
          markTemplateId: '', // 自定义模板id
          businessBatchConfig: [], // 业务线创建批次配置
          businessPageType: '0',
          pageVersion: '', // 标注版本
        }
      },
      flow: [
        {
          step: 0,
          recovery: {
            isSubmitProcessed: true // 提交已标注
            // removeStatus: '0' // 删除文件类型// "0"/"1"/"-1"   默认值：0
          },
          giveup: {
            // isSubmitProcessed: false, // 是否提交已标注:  默认值false
            // isRemoveResult: false // 是否删除result表中的结果
            isUpdateResult: true // 是否更新file中默认结果
            // removeStatus: '-1'// 删除文件类型// "0"/"1"/"-1"   默认值：-1
          },
          transfer: {
            isSubmitProcessed: true // 是否提交已处理的:  默认值true
            // isRemoveResult: false, // 是否删除result表中的结果
            // removeStatus: '0'// 删除文件类型// "0"/"1"/"-1"   默认值：0
          }
        },
        {
          step: 1,
          recovery: {
            isRemoveResult: true // 提交已标注
            // removeStatus: '0' // 删除文件类型// "0"/"1"/"-1"   默认值：0
          },
          giveup: {
            // isSubmitProcessed: false, // 是否提交已标注:  默认值false
            isSaveResult: false // 是否保存result表中的结果
            // isUpdateResult: false, // 是否更新file中默认结果
            // removeStatus: '-1'// 删除文件类型// "0"/"1"/"-1"   默认值：-1
          },
          transfer: {
            isRemoveResult: true // 是否提交已处理的:  默认值true
            // isRemoveResult: false, // 是否保存result表中的结果
            // removeStatus: '0'// 删除文件类型// "0"/"1"/"-1"   默认值：0
          }
        },
        {
          step: 2,
          recovery: {
            isRemoveResult: true // 提交已标注
            // removeStatus: '0' // 删除文件类型// "0"/"1"/"-1"   默认值：0
          },
          giveup: {
            // isSubmitProcessed: false, // 是否提交已标注:  默认值false
            isSaveResult: false // 是否保存result表中的结果
            // isUpdateResult: false, // 是否更新file中默认结果
            // removeStatus: '-1'// 删除文件类型// "0"/"1"/"-1"   默认值：-1
          },
          transfer: {
            isRemoveResult: true // 是否提交已处理的:  默认值true
            // isRemoveResult: false, // 是否删除result表中的结果
            // removeStatus: '0'// 删除文件类型// "0"/"1"/"-1"   默认值：0
          }
        }
      ],
      taskflowNode: [
        'createBatchTaskFlowId',
        'taskExportTaskFlowId',
        'createMedalTaskFlowId'
      ],
      cname: {
        // 节点名称
        createBatchTaskFlowId: '创建批次任务流',
        taskExportTaskFlowId: '导出任务流',
        createMedalTaskFlowId: '勋章导入题库',
        recoveryStrategy: '回收策略',
        transferStrategy: '转移策略',
        integralHandle: '积分设置',
        viewMarkPage: '标注界面',
        viewCreateBatch: '创建批次',
        viewCreateMedal: '创建勋章',
        viewExport: '导出',
        viewMarkTaskPage: '标注任务查看',
        viewMedalPage: '勋章标注',
        viewMyIntegralDetail: '积分详情',
        viewResultPage: '查看结果'
      },
      historyViewList: {
        // 路由历史
        viewMarkPage: [],
        viewCreateBatch: [],
        viewCreateMedal: [],
        viewExport: [],
        viewMarkTaskPage: [],
        viewMedalPage: [],
        viewMyIntegralDetail: [],
        viewResultPage: []
      },
      loading: false, // 提交按钮 loading 显示状态
      searchValue: '', // 工作流快捷检索
      pipelineList: null, // 可选工作流列表
      outerVisual: false, // 批次配置项弹窗显示隐藏
      conifgInfo: conifgInfo, // 业务线配置列表数据
      configInfoHash: {}, // 业务线配置列表hash表
      templateList: [], // 模板列表
      tmpVersionList: [], // 模板版本列表
      generalRouterPath: '{}', // 通用路由地址
    }
  },
  computed: {
    // 业务线批次配置选择过滤
    filterConifgInfo() {
      return this.conifgInfo.filter(item => this.busSetting.viewConfig.businessBatchConfig.indexOf(item.ename) > -1)
    }
  },
  methods: {
    recoveryChange(value) {
      this.flow[0].recovery.isSubmitProcessed = value
    },
    transferChange(value) {
      this.flow[0].transfer.isSubmitProcessed = value
    },
    giveupMark(value) {
      this.flow[0].giveup.isUpdateResult = value
    },
    giveupCheck(value) {
      this.flow[1].giveup.isSaveResult = value
    },
    giveupTest(value) {
      this.flow[2].giveup.isSaveResult = value
    },
    back() {
      this.$router.push({ path: '/home/linemanage/linelist' })
    },
    changeFlowTask(item) {
      for (let i = 0; i < this.pipelineList.length; i++) {
        if (item.value === this.pipelineList[i].id) {
          item.Name = this.pipelineList[i].name
        }
      }
    },
    handleAdd() {
      this.busSetting.flowTask.push({
        value: '',
        Name: ''
      })
    },
    handleRemove(index) {
      this.busSetting.flowTask.splice(index, 1)
    },
    getBusDetail() {
      getListDetail(this.modelId)
        .then(async res => {
          console.log(res, 'rrrrrrrres////')
          if (res) {
            if (res.data.tasks == null) {
              this.$Message.error('获取tasks失败')
              //   return;
            }
            if (res.data.views == null) {
              this.$Message.error('获取views失败,前端是否还没传页面呢？')
              // return;
            }
            this.modelId = res.data.modelId
            if (res.data.isNew) {
              this.busSetting.isNew = res.data.isNew
            }
            this.busSetting.modeName = res.data.modeName
            this.busSetting.describe = res.data.describe
            this.busSetting.modelId = res.data.modelId
            this.busSetting.modelType = res.data.modelType
            if (res.data.flowTask) {
              this.busSetting.flowTask = res.data.flowTask
            }
            if (res.data.viewConfig) {
              let {businessPageType, businessBatchConfig} = res.data.viewConfig
              // 处理业务线批次配置数据
              if (businessBatchConfig) {
                this.busSetting.viewConfig.businessBatchConfig = [];
                businessBatchConfig.forEach(item => {
                  if (!item || !item.ename) return;
                  this.busSetting.viewConfig.businessBatchConfig.push(item.ename)
                })
              }

              // 业务线方向操作
              if (businessPageType) {
                this.busSetting.viewConfig.businessPageType = businessPageType
              }
              // 调接口 获取模板信息
              if (this.busSetting.viewConfig.businessPageType === '1') {
                let {markTemplateId, pageVersion} = res.data.viewConfig
                await this.businessCheckType('init') // 获取自定义模板列表
                await this.selectTmp(markTemplateId) // 获取当前模板的版本
                if (pageVersion) {
                  this.busSetting.viewConfig.pageVersion = pageVersion
                }
                this.busSetting.viewConfig.markTemplateId = markTemplateId
              } else if (this.busSetting.viewConfig.businessPageType === '0') {
                this.generalRouterPath = JSON.stringify(this.busSetting.views) // 缓存原始线路径
              }
            }
            this.$set(this.busSetting, 'tasks', res.data.tasks)
            this.$set(this.busSetting, 'views', res.data.views)
            // Object.keys(res.data.views).forEach(key=>{
            //   this.busSetting.views[key] = res.data.views[key]
            // })
            this.getBusKeys()

            if (this.busSetting.tasks.flow && this.busSetting.tasks.flow.length === 3) {
              this.flow = this.busSetting.tasks.flow
            }
          }
        })
        .catch(err => {
          this.$Message.error('获取当前业务信息失败！详细信息：' + err)
        })
    },
    getBusKeys() {
      getKeys(this.modelId)
        .then(res => {
          if (res) {
            if (res.data.length === 0) {
              Object.keys(this.historyViewList).forEach(key => {
                this.historyViewList[key].push(this.busSetting.views[key])
              })
              return;
            }
            this.$set(this, 'historyViewList', {})
            for (let i = 0; i < res.data.length; i++) {
              let item = res.data[i].views
              for (var k in item) {
                // arr.push(item[k])
                if (this.historyViewList[k]) {
                  this.historyViewList[k].push(item[k])
                } else {
                  this.historyViewList[k] = []
                }
              }
            }
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    saveBusiness() {
      // 提交校验
      if (!this.submitCheck()) return;
      this.loading = true
      if (!this.busSetting.tasks) {
        this.$set(this.busSetting, 'tasks', {})
        this.$set(this.busSetting.tasks, 'createBatchTaskFlowId', '')
        this.$set(this.busSetting.tasks, 'taskExportTaskFlowId', '')
        this.$set(this.busSetting.tasks, 'recoveryStrategy', '')
        this.$set(this.busSetting.tasks, 'transferStrategy', '')
        this.$set(this.busSetting.tasks, 'createMedalTaskFlowId', '')
      }
      delete this.flow[1].giveup.isRemoveResult;
      delete this.flow[2].giveup.isRemoveResult;
      this.$set(this.busSetting.tasks, 'flow', this.flow)

      // 深拷贝保存值
      let copeBusSetting = this.busSetting
      // 业务线批次配置数据设置保存值
      let { businessBatchConfig } = copeBusSetting.viewConfig
      copeBusSetting.viewConfig.businessBatchConfig = businessBatchConfig.map(item => this.configInfoHash[item])
      saveListDetail({
        id: this.busSetting.modelId,
        modelType: this.busSetting.modelType,
        data: this.busSetting
      })
        .then(res => {
          if (res) {
            this.$Message.success('很棒，添加成功了！')
            this.$router.push({ path: '/home/linemanage/linelist' })
          }
          this.loading = false
        })
        .catch(err => {
          this.$Message.error('添加失败，快看看接口咋地了？详细信息：' + err)
          this.loading = false
        })
    },
    submitCheck() {
      // 自定义业务线方向
      if (this.busSetting.viewConfig.businessPageType === '1') {
        if (!this.busSetting.viewConfig.markTemplateId) {
          this.$Message.error('请选择自定义标注模板')
          return false;
        }
        if (!this.busSetting.viewConfig.pageVersion) {
          this.$Message.error('请选择自定义标注模板版本')
          return false;
        }
      }
      return true
    },
    // 查询工作流列表
    getPipeline() {
      let param = {
        name: this.searchValue,
        pageIndex: 1,
        pageSize: 100
      }
      getPipeline(param).then(res => {
        if (res) {
          this.pipelineList = res.data.pipelineStates
        }
      })
    },
    // 业务线批次配置项 选择确定
    outerOkHandler() {
      this.outerVisual = false;
    },
    // 业务线批次配置项 关闭
    outerCancelHandler() {
      this.outerVisual = false;
    },
    // 选择配置
    openOuterConfig() {
      this.outerVisual = true;
    },
    handleClose(tags) {
      let delTagEname = tags.ename
      let delTagInd = this.busSetting.viewConfig.businessBatchConfig.indexOf(delTagEname)
      if (delTagInd > -1) {
        this.busSetting.viewConfig.businessBatchConfig.splice(delTagInd, 1)
      }
    },
    // 初始化批次业务线配置列表数据
    initBatchConfigList() {
      // 生成hash 避免每次循环遍历
      this.conifgInfo.forEach(item => {
        this.configInfoHash[item.ename] = item
      })
    },
    // 改变业务线类型
    /**
     * @param type label切换的类型 初始化时切换 or 点击label时切换
     */
    businessCheckType(type) {
      let { businessPageType } = this.busSetting.viewConfig
      if (businessPageType === '1') { // 自定义业务线
        let param = { // 下拉框 无滚动加载 写死最大值
          page: 1,
          size: 2000
        };
        getTemplateList(param).then(res => {
          if (res) {
            this.templateList = res.items;
          }
        })
          .catch(err => {
            this.$Message.error(err);
          })
        // 先缓存原始线路径
        type != 'init' ? this.generalRouterPath = JSON.stringify(this.busSetting.views) : ''
        // 生成页面路由
        this.GenerateCustomUrl()
      } else if (businessPageType === '0') {
        let generalRouters = JSON.parse(this.generalRouterPath)
        // 生成页面路由
        Object.keys(this.busSetting.views).forEach(key => {
          this.busSetting.views[key] = generalRouters[key] ? generalRouters[key] : ''
        })
      }
    },
    // 选择完模板后处理
    async selectTmp(tmpid) {
      // tmpVersionList
      this.busSetting.viewConfig.pageVersion = ''
      let res = await getTemplateListVersion({ id: tmpid, page: 1, size: 1000 });
      if (res && res.items.length) {
        this.tmpVersionList = res.items
      } else {
        this.tmpVersionList = []
      }
    },
    /**
     * 自定义标注生成访问路径
     * @param type 生成路径类型 原始线路径生成 or 自定义线路径生成
     * @param version 自定义模板版本号
     */
    GenerateCustomUrl() {
      let { markTemplateId, pageVersion } = this.busSetting.viewConfig
      let vstate = (markTemplateId && pageVersion !== undefined)
      let path = {
        viewMarkPage: vstate ? `/home/mark-page/${pageVersion}/${markTemplateId}` : '',
        viewCreateBatch: vstate ? `/home/create-batch/${pageVersion}/${markTemplateId}` : '',
        viewCreateMedal: vstate ? `/home/create-medal/${pageVersion}/${markTemplateId}` : '',
        viewExport: vstate ? `/home/export/${pageVersion}/${markTemplateId}` : '',
        viewMarkTaskPage: vstate ? `/home/marktask-detail/${pageVersion}/${markTemplateId}` : '',
        viewMedalPage: vstate ? `/home/medal-page/${pageVersion}/${markTemplateId}` : '',
        viewMyIntegralDetail: vstate ? `/home/myintegral-detail/${pageVersion}/${markTemplateId}` : '',
        viewResultPage: vstate ? `/home/result-page/${pageVersion}/${markTemplateId}` : ''
      }
      let { views } = this.busSetting
      Object.keys(views).forEach(key => {
        this.busSetting.views[key] = path[key]
      })
    },
    // 自定义模板版本选择
    selectVersion(v) {
      if (v === undefined) return;
      // 当前时哪个方向选择版本，自定义还是原始线
      let { businessPageType } = this.busSetting.viewConfig
      if (businessPageType === '0') { // 通用原始
        // 生成页面路由
        let vInd = this.historyViewList.viewMarkPage.indexOf(v)
        Object.keys(this.busSetting.views).forEach(key => {
          this.busSetting.views[key] = this.historyViewList[key] ? this.historyViewList[key][vInd] : ''
        })
      } else if (businessPageType === '1') {
        // 生成页面路由
        this.GenerateCustomUrl()
      }
    }
  },
  created() {
    if (this.$route.query.edit) {
      this.edit = true
    }
    if (this.$route.query.modelId) {
      this.modelId = this.$route.query.modelId
      this.getBusDetail()
    }
    // 初始化批次配置列表
    this.initBatchConfigList()
    this.getPipeline()
  },
  mounted() { }
}
</script>

<style rel="stylesheet/less" lang="less" scoped>
.businessForm {
  border-top: 1px solid #d6d6d6;
  .title {
    padding-left: 140px;
    font-size: 16px;
    line-height: 40px;
    font-weight: bold;
    padding-top: 20px;
  }
  .box {
    border-bottom: 1px dashed #d6d6d6;
  }
}
.line-detail {
  .table-blue {
    display: inline-block;
    margin: 20px;
    font-size: 12px;
    .icon-left {
      font-size: 12px;
    }
  }
}
</style>

<style lang="less">
.visual-outer-model {
  .ivu-modal-body {
    padding-bottom: 72px;
  }
  .visual-outer-footer {
    float: right;
    margin-top: 20px;
  }
  .ivu-checkbox-wrapper {
    margin-bottom: 10px;
    margin-right: 10px;
  }
  .outer-name {
    .ivu-input-wrapper {
      width: 280px;
    }
  }
}
</style>
